<% var fromDate = new Date(dateStr); %>
<% var today = new Date(); %>

<tbody>
<% var rowIndex = 0; %>
<% value.each(function (roomInfo) { %>
    <tr data-roomid=<%=roomInfo.attributes.roomId%> data-roomtype=<%=roomInfo.attributes.roomType%> data-roomnumber=<%=roomInfo.attributes.roomNumber%> data-roomtypeid=<%=roomInfo.attributes.roomTypeId%>>
        <% for(var i=0; i<30; i++) { %> 
            <% var indexDate = new Date(fromDate.getFullYear(), fromDate.getMonth(), fromDate.getDate() + i);%>
            <% var orders = roomInfo.attributes.orders; %>
            <% if(orders != null && orders != undefined) { %>
                <% var order = orders.find(function (o) { %>
                    <% var fromDate = new Date(o.attributes.fromRNightDate.replace(/-/g, "/")); %>
                    <% var toDate = new Date(o.attributes.toRNightDate.replace(/-/g, "/")); %>
                    <% return indexDate >= fromDate && indexDate <= toDate; %>
                <% }); %>

                <% if(order != null && order != undefined){ %>
                    <% if(order.attributes.roomStatus === 'Booked'){ %> 
                        <td class="booked" style="cursor: pointer;" data-status="booked" data-date=<%= indexDate.yyyyMMdd()%> data-roomid=<%= roomInfo.attributes.roomId%> data-orderid=<%= order.attributes.orderId%>>
                            <div class="bookedInfo">
                                <div>预定</div>
                                <div><%= order.attributes.reserverName%></div>
                            </div>
                        </td>
                    <% } else if(order.attributes.roomStatus === 'CheckedIn') { %>
                        <td class="checkedin" style="cursor: pointer;" data-status="checkedin" data-date=<%= indexDate.yyyyMMdd()%> data-roomid=<%= roomInfo.attributes.roomId%> data-orderid=<%= order.attributes.orderId%>>
                            <div class="checkedinInfo">
                                <div>已入住</div>
                                <div><%= order.attributes.reserverName%></div>
                            </div>
                        </td>
                    <% } else if(order.attributes.roomStatus === 'Away') {%>
                         <td class="away" style="cursor: pointer;" data-status="away" data-date=<%= indexDate.yyyyMMdd()%> data-roomid=<%= roomInfo.attributes.roomId%> data-orderid=<%= order.attributes.orderId%>>
                            <div class="awayInfo">
                                <div>已离店</div>
                                <div><%= order.attributes.reserverName%></div>
                            </div>
                        </td>
                    <% } else if(order.attributes.roomStatus === 'Locked') {%>
                         <td class="locked" style="cursor: pointer;" data-status="locked" data-date=<%= indexDate.yyyyMMdd()%> data-roomid=<%= roomInfo.attributes.roomId%> data-orderid=<%= order.attributes.orderId%>>
                            <div class="lockedInfo">
                                <div>已关闭</div>
                                <div><%= order.attributes.reserverName%></div>
                            </div>
                        </td>
                    <% } %>
                <% } else { %>
                    <td class="bookable" style="cursor: pointer;" data-status="bookable" data-dailyPrice=<%= roomInfo.attributes.dailyPrices[i]%> data-x=<%= rowIndex%> data-y=<%= i%> data-date=<%= indexDate.yyyyMMdd()%>>
                        <div class="bookableInfo" style="display: none">
                            <div><%=roomInfo.attributes.roomType%></div>
                            <div><%=roomInfo.attributes.roomNumber%></div>
                            <div><dnf>¥<%=this.parseFloat(roomInfo.attributes.dailyPrices[i]).toFixed(2)%></dnf></div>
                        </div>
                    </td>
                <% } %>
            <% } %>
        <% } %> 
    </tr>
    <% rowIndex++;%>
    <% }); %>
</tbody>
